use bevy::prelude::*;
use bevy::app::{App, Plugin, Startup, Update};
use bevy::time::common_conditions::on_timer;

use std::time::Duration;
use crate::tutorials::bevy::res::my_assets::*;
use crate::tutorials::bevy::res::my_res::*;
use crate::tutorials::bevy::systems::{data_init_sys, game_sys, log_sys};

pub struct HelloPlugin;

impl Plugin for HelloPlugin {
    fn build(&self, app: &mut App) {
        app
        // .insert_resource(GreetTimer(Timer::from_seconds(2.0, TimerMode::Repeating)))
        // .add_systems(Startup, data_init_sys::add_people)
        // .add_systems(Update, (game_sys::update_people, game_sys::greet_people).chain())
        
        // .add_systems(Startup, data_init_sys::setup_wireframe)
        // .add_systems(Update, game_sys::toggle_wireframe)

        // .add_systems(Startup, data_init_sys::setup_2d_viewport)
        // .add_systems(FixedUpdate, game_sys::controls_2d_viewport)
        // .add_systems(PostUpdate,
        //     game_sys::draw_cursor_2d_viewport.after(TransformSystem::TransformPropagate),
        // )

        // .add_systems(Startup, data_init_sys::setup_bloom)
        // .add_systems(Update, game_sys::update_bloom_settings)

        // .add_observer(game_sys::disable_entities_on_click)
        // .add_systems(Startup, (data_init_sys::setup_scene_for_disable, data_init_sys::display_instructions))
        // .add_systems(Update, (game_sys::list_all_named_entities, game_sys::reenable_entities_on_space))

        // .init_resource::<SpatialIndex>()
        // .add_systems(Startup, data_init_sys::setup_mine)
        // .add_systems(Update, (game_sys::draw_shapes_mine, game_sys::handle_click_mine))
        // // Observers are systems that run when an event is "triggered". This observer runs whenever
        // // `ExplodeMines` is triggered.
        // .add_observer(game_sys::explode_mines_cascade)
        // // This observer runs whenever the `Mine` component is added to an entity, and places it in a simple spatial index.
        // .add_observer(game_sys::on_add_mine)
        // // This observer runs whenever the `Mine` component is removed from an entity (including despawning it)
        // // and removes it from the spatial index.
        // .add_observer(game_sys::on_remove_mine)

        // .add_systems(Startup, data_init_sys::setup_ob_propagation)
        // .add_systems(Update, game_sys::attack_armor.run_if(on_timer(Duration::from_millis(200))))
        // // Add a global observer that will emit a line whenever an attack hits an entity.
        // .add_observer(game_sys::attack_hits)

        // .insert_resource(ClearColor(Color::BLACK))
        // .add_systems(Startup, data_init_sys::generate_bodies)
        // .add_systems(FixedUpdate, (game_sys::interact_bodies, game_sys::integrate).chain())
        // .add_systems(Update, game_sys::look_at_star)

        // .add_systems(Startup, data_init_sys::setup_subview)
        // .add_systems(Update, (game_sys::move_camera_view, game_sys::resize_viewports))
        
        // .add_plugins(MaterialPlugin::<CustomMaterialEmpty>::default())
        // .add_systems(Startup, data_init_sys::setup_material_shader)

        .add_plugins(MaterialPlugin::<CustomMaterialImage>::default())
        .add_systems(Startup, data_init_sys::setup_instanced)
        .add_systems(Update, game_sys::update_instanced)
        ;
    }
}